/**
 * Created by jiachenpan on 16/11/18.
 */

/* 合法uri*/
export function validateURL(textval) {
    const urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
    return urlregex.test(textval)
  }
  
  /* 小写字母*/
  export function validateLowerCase(str) {
    const reg = /^[a-z]+$/
    return reg.test(str)
  }
  
  /* 大写字母*/
  export function validateUpperCase(str) {
    const reg = /^[A-Z]+$/
    return reg.test(str)
  }
  
  /* 大小写字母*/
  export function validatAlphabets(str) {
    const reg = /^[A-Za-z]+$/
    return reg.test(str)
  }
  
  /* 字母数字*/
  export function azAZ09(str)
  {
    const reg = /^[A-Za-z0-9]+$/
    return reg.test(str)
  }
  /* 字母数字下划线*/
  export function _azAZ09(str)
  {
    const reg = /^[_A-Za-z0-9]+$/
    return reg.test(str)
  }
  /* 纯数字*/
  export function validatNums(str) {
    const reg = /^[0-9]+$/
    return reg.test(str)
  }
  export function validatZhengNums(str) {
    const reg = /^[1-9]+[0-9]*$/
    return reg.test(str)
  }
  
  /* 正整数*/
  export function positiveNum(str) {
    const reg = /^[1-9]+\d*$/
    return reg.test(str)
  }
  
  /* 验证账号*/
  export function validatUserName(str) {
    const reg = /^[a-zA-Z0-9]+$/
    return reg.test(str)
  }
  
  /* 验证手机号 */
  export function validatMobile(str) {
    const reg = /^1[3456789]\d{9}$/
    return reg.test(str)
  }
  /* 验证金额 */
  export function validatMoney(str) {
    if (str == 0.00) return false
    const reg = /^[0-9]+[\.]?[0-9]{0,2}$/
    return reg.test(str)
  }
  /* 验证运费数字 */
  export function validatDeliver(aaa) {
    if (aaa == null || aaa.length < 1) 
      return false
    const reg = /^[0-9]+[\.]?[0-9]{0,2}$/
    return reg.test(aaa)
  }
  /* 验证邮箱 */
  export function validatEmail(str) {
    const reg = /^[\w-]+@[\w-]+(\.\w+){1,3}$/
    return reg.test(str)
  }
  export function isValidIP(ip) {
    var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
    return reg.test(ip);
  } 